﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ToolKit.Mvvm.Helpers
{
    public class FileHelper
    {
        private static string extensionName = ".dll";
        public static List<Assembly> GetAssemblies(string path)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(path);
            if (directoryInfo.Exists)
            {
                // 获取文件夹中的文件列表
                var files = directoryInfo.GetFiles().Where(t => t.Extension.ToLower() == extensionName.ToLower()).ToList();
                //定义返回结果
                List<Assembly> assemblies = new List<Assembly>();
                //追加返回结果
                files.ForEach(t => assemblies.Add(Assembly.LoadFrom(t.FullName)));
                return assemblies;
            }

            return new List<Assembly>();
        }
    }
}
